#include "Line.h"
#include <cmath>
#define PI 3.14159265

Line::Line(void)
{

}


vector<Point> Line::MakeLine(Point p1, Point p2)
{
	int NumPoints=10;						 // defines size of vector "points"	**		
	vector<Point> points ;		 
	Point temp=p1;

	// working variables for making line
	float xDelt,yDelt,zDelt;
	xDelt = (p2.x-p1.x)/NumPoints;
	yDelt = (p2.y-p1.y)/NumPoints;
	zDelt = (p2.z-p1.z)/NumPoints;
	

	for (int it=0;	it<NumPoints;	it++)
	{
		temp.x=xDelt+temp.x;
		temp.y=yDelt+temp.y;
		temp.z=zDelt+temp.z;
    	points.push_back(temp);
	}

	return points;
}

/*start: starting point on the arc 
  radius: radius of the arc
  degreeArc: how far the arc extends
  degreeInc: incline of the arc with respect to xy-plane
  degreeTilt: tilt of arc with respect to yz-plane
  numPoints: number of points on the arc
  check out arc.png (same folder as main.cpp) for more details

  To work in the 2D xy-plane set degreeTilt = 0;
  For function to work properly NEED       degreeArc/numPoint >=1,        at least one degree per point, safest to set numPoint = 360;
*/
vector<Point> Line::MakeArc(Point start, float radius, float degreeArc, float degreeInc, float degreeTilt, int numPoints)
{
	vector<Point> pointsArc;
	degreeInc=degreeInc*PI/180;		//change to radians
	degreeArc=degreeArc*PI/180;
	degreeTilt=degreeTilt*PI/180;
	float degreeDelta = degreeArc/numPoints;
	float xDelta = 0;
	float yDelta = 0;
	float zDelta = 0;

	Point nextPoint0(0,0,0);
	Point nextPoint1(0,0,0);
	Point offset(0,0,0);
		
	for (int n=0; n<numPoints; n++)
	{
	xDelta = radius*(cos(degreeDelta*(n+1))-1);
	yDelta = radius*(sin(degreeDelta*(n+1)));
	
	nextPoint1.z=0;
	nextPoint1.x=xDelta+start.x;
	nextPoint1.y=yDelta+start.y;
	
	
	//Rotate about z degreeIncline
	nextPoint0.x = nextPoint1.x*cos(degreeInc)-nextPoint1.y*sin(degreeInc);
	nextPoint0.y = nextPoint1.x*sin(degreeInc)+nextPoint1.y*cos(degreeInc);
	nextPoint0.z = 0;
	//Rotate about x degreeTilt
	nextPoint1.x = nextPoint0.x;
	nextPoint1.y = nextPoint0.y*cos(degreeTilt)-nextPoint0.z*sin(degreeTilt);
	nextPoint1.z = nextPoint0.y*sin(degreeTilt)+nextPoint0.z*cos(degreeTilt);
	//Reposition back to original position
	if (n==0)
	{ 
		offset.x=nextPoint1.x-start.x;
		offset.y=nextPoint1.y-start.y;
		offset.z=nextPoint1.z-start.z;
	}
	nextPoint0.x = nextPoint1.x-offset.x;
	nextPoint0.y = nextPoint1.y-offset.y;
	nextPoint0.z = nextPoint1.z-offset.z;


	pointsArc.push_back(nextPoint0);
	
	
	}
	

	return pointsArc;
}

